import axios from "axios";

import type {
    AxiosInstance,
    AxiosRequestConfig,
    InternalAxiosRequestConfig,
    AxiosResponse,
} from "axios";

const axiosInstanceForHiglass: AxiosInstance = axios.create({
    baseURL: process.env.NEXT_PUBLIC_HIGLASS_URL, // 根据实际情况配置 baseURL
    timeout: 50000, // 设置超时时间
});

// 请求拦截器
axiosInstanceForHiglass.interceptors.request.use(
    (config: InternalAxiosRequestConfig) => {
      // 在这里添加请求拦截逻辑，例如添加 token 等
      config.headers['Content-Type'] = "application/json" // 设置Content-Type
      return config;
    },
    (error) => {
      return Promise.reject(error);
    }
);
  
// 响应拦截器
axiosInstanceForHiglass.interceptors.response.use(
    (response: AxiosResponse) => {
        // 在这里添加响应拦截逻辑，例如处理错误信息等
        return response;
    },
    (error) => {
        return Promise.reject(error);
    }
);

export default axiosInstanceForHiglass;
